//
//  TwitterPoster.m
//  Radio Streaming app
//
//  Created by HaiNguyenThanh on 4/19/11.
//  Copyright 2011 VinaSource. All rights reserved.
//

#import "TwitterPoster.h"
#import "AppDelegate_iPhone.h"

@implementation TwitterPoster
@synthesize username;
@synthesize loginDelegate;
@synthesize mOuathLogin;

- (id) init
{
	if (self == [super init])
	{
		mOuathLogin = [[OuathAuthViewController alloc]init];
	}
	return self;
}

// Get twitter user name
- (NSString*)username
{
	return [mOuathLogin returnUserName];
}

- (void) logout
{
	[mOuathLogin logoutOfTwitter];
	[loginDelegate logOff];
	[[NSUserDefaults standardUserDefaults] setObject:NULL forKey:KTWITTER_SCREEN_NAME];
}

/*
 * Return Yes if user loged in, return NO if user not login yet.
 */
- (BOOL)isLogedIn
{
	if (mOuathLogin._engine == nil)
	{
		return NO;
	}
	
	return YES;
}

#pragma mark -
#pragma mark Twitter Delegate Methods
- (void)login:(id)delegate
{
	if(mOuathLogin == nil)
	{
		mOuathLogin = [OuathAuthViewController alloc] ;
	}
	if(delegate)
		mOuathLogin.delegate = self;
	[mOuathLogin Login:delegate];
}

- (void) twit:(NSString*)text withLink:(NSString*)link forapp:(NSString *)twitAppname makeTiny:(BOOL)yesOrno delegate:(id)delegate
{
	if(mOuathLogin == nil)
	{
		mOuathLogin = [OuathAuthViewController alloc] ;
	}
	if(delegate)
	{
		mOuathLogin.delegate = delegate;
	}
	NSString *s = text;		
	//[mOuathLogin twit:s withLink:link forapp:twitAppname makeTiny:yesOrno :mainiPhoneAppDelegate.rootViewController.mainNavController];	
}

-(void)didAuthenticatedWithUserName:(NSString *)userName
{
	username = [NSString stringWithFormat:@"%@", userName];
	[userName retain];
	[loginDelegate getUserInfoTwitter];
}

-(void)didAuthenticatedCancel
{
	DEBUG_LOG(@"Authenticate Cancel");
}

@end
